package cn.zqh.commodity.config;

import cn.zqh.bean.api.CommonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: zqh
 * @Date: 2023-01-09-9:16
 * @Description: 全局异常处理$
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public CommonResult error(Exception e){
          e.printStackTrace();
          return CommonResult.failed();
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public CommonResult error(ArithmeticException e){
        e.printStackTrace();
        return CommonResult.failed("特殊异常处理");
    }

    @ExceptionHandler(BSException.class)
    @ResponseBody
    public CommonResult error(BSException e){
        e.printStackTrace();
        return CommonResult.failed(e.getMsg());
    }

}
